
<script>
// 1
const p=new Promise((resolve,reject)=>{
    console.log('初始化')
    resolve()
})
.then(()=>{
    throw new Error('有哪里不对了')
    console.log('执行这个');
})
.catch(()=>{
    console.log('执行那个');
})
.then(()=>{
    console.log('执行这个，无论前面发生了什么');
})


// 2
function myAsyncFunction(url){
    return new Promise((resolve,reject)=>{
        const xhr=new XMLHttpRequest();
        xhr.open('GET',url);
        xhr.onload=()=>resolve(xhr.responseText)
        xhr.onerror=()=>reject(xhr.statusText)
        xhr.send()
    })
}
myAsyncFunction('试一个本地文件地址').then(text=>console.log(text))

//3
let myFirstPromise=new Promise(function(resolve,reject){
    setTimeout(function(){
        resolve('成功')
    },250)
})
myFirstPromise.then(function(successMessage){
    console.log('Yay!'+successMessage);
})
//4


</script>